using System;
using System.Data;

namespace FreeFlow.Administration
{
  /*/// <summary>
  /// The type of a field on a form
  /// </summary>
  public enum FieldType
  {
    /// <summary>An attachment field</summary>
    Attachment,
    /// <summary>A command button</summary>
    Button,
    /// <summary>A checkbox field</summary>
    Check,
    /// <summary>A currency field</summary>
    Currency,
    /// <summary>A dataset field</summary>
    Dataset,
    /// <summary>A date-time field</summary>
    DateTime,
    /// <summary>A grid field</summary>
    Grid,
    /// <summary>An image field</summary>
    Image,
    /// <summary>A label field</summary>
    Label,
    /// <summary>A memo field</summary>
    Memo,
    /// <summary>A number field</summary>
    Number,
    /// <summary>An option field (drop-down, list or radio-group)</summary>
    Option,
    /// <summary>A rule field</summary>
    Rule,
    /// <summary>A signature field</summary>
    Signature,
    /// <summary>A status field</summary>
    Status,
    /// <summary>A text field</summary>
    Text
  }*/

	/// <summary>
	/// A field on a form.
	/// </summary>
	public class Field
	{
		internal Field(IDataReader reader)
		{
      name = reader["eFieldName"].ToString();
      dataValue = reader["eDataValue"].ToString();
      whenChanged = reader["eOnUpdate"].ToString();
      isDependent = Convert.ToBoolean(reader["eDependent"]);
      autoRefill = Convert.ToBoolean(reader["eHasDependants"]);
      options = reader["eOptions"].ToString();
      columnList = reader["eColumnList"].ToString();
      id = Convert.ToInt16(reader["eFieldID"]);
      dataSet = reader["eDataSet"].ToString();

//      fieldType = ReadFieldType(Convert.ToInt32(reader["eFieldType"]), 
//        Convert.ToInt32(reader["eDataType"]), Convert.ToInt32(reader["eAttachments"]));
		}

//    private FieldType ReadFieldType(int fieldType, int dataType, int attachments)
//    {
//      switch (fieldType)
//      {
//        case 1 : return FieldType.Rule;
//        case 2 : return FieldType.Label;
//        case 3 : return FieldType.Button;
//        case 4 : return ReadDataType(dataType, attachments);
//        case 5 : 
//          if (id == 0)
//            return FieldType.Image;
//          else
//            return ReadDataType(dataType, attachments);
//        case 6 : return FieldType.Grid;
//        case 7 : return FieldType.Status;
//        case 8 : return FieldType.Dataset;
//        default : throw new FreeFlowException("Unexpected field type - " + fieldType);
//      }
//    }

//    private FieldType ReadDataType(int dataType, int attachments)
//    {
//      switch (dataType)
//      {
//        case 1 : return FieldType.Check;
//        case 2 : return FieldType.Option;
//        case 3 :
//        case 4 : return FieldType.Number;
//        case 5 : return FieldType.DateTime;
//        case 6 : return FieldType.Grid;
//        case 7 : return FieldType.Currency;
//        case 8 : 
//          if (attachments == 1)
//            return FieldType.Attachment;
//          else
//            return FieldType.Text;
//        case 9 : return FieldType.Signature;
//        default : throw new FreeFlowException("Unexpected data type - " + dataType);
//      }
//    }

    private string name;
    /// <summary>
    /// Gets the name of the field.
    /// </summary>
    public string Name
    {
      get
      {
        return name;
      }
    }

//    private FieldType fieldType;
    /// <summary>
    /// Gets the type of the field.
    /// </summary>
//    public FieldType FieldType
//    {
//      get
//      {
//        return fieldType;
//      }
//    }

    private string dataValue;
    /// <summary>
    /// Gets the code evaluated to get the value of the field.
    /// </summary>
    /// <value>The data value.</value>
    public string DataValue
    {
      get
      {
        return dataValue;
      }
    }

    private string whenChanged;
    /// <summary>
    /// Gets the code that will be evaluated when the field has changed.
    /// </summary>
    public string WhenChanged
    {
      get
      {
        return whenChanged;
      }
    }

    private bool isDependent;
    /// <summary>
    /// Gets a value indicating whether this field will be recalculated during a refill.
    /// </summary>
    /// <value>
    /// 	<c>true</c> if this field will be recalculated during a refill; otherwise, <c>false</c>.
    /// </value>
    public bool IsDependent
    {
      get
      {
        return isDependent;
      }
    }

    private bool autoRefill;
    /// <summary>
    /// Gets a value indicating whether altering this field will cause a refill.
    /// </summary>
    /// <value>
    /// 	<c>true</c> if altering this field will cause a refill; otherwise, <c>false</c>.
    /// </value>
    public bool AutoRefill
    {
      get
      {
        return autoRefill;
      }
    }

    private string options;
    /// <summary>
    /// Gets the formula that will be evaluated for the options for the field.
    /// </summary>
    public string Options
    {
      get
      {
        return options;
      }
    }

    private string columnList;
    /// <summary>
    /// Gets the formula that will be evaluated to generate the XML column list for a grid.
    /// </summary>
    public string ColumnList
    {
      get
      {
        return columnList;
      }
    }

    private int id;
    /// <summary>
    /// Gets the ID of the field.
    /// </summary>
    public int Id
    {
      get
      {
        return id;
      }
    }

    private string dataSet;
    /// <summary>
    /// Gets the dataset that this field gets its data from.
    /// </summary>
    public string DataSet
    {
      get
      {
        return dataSet;
      }
    }
	}
}
